package com.htdc.web.service;

import com.htdc.web.bean.ProjectTb;
import com.htdc.web.bean.Room;
import com.htdc.web.dao.ProjectDao;
import com.htdc.web.dao.RoomDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Sfx
 * Date: 2018/9/5 0005
 * Time: 上午 11:05
 * To change this template use File | Settings | File Templates.
 */
@Service
public class RoomService {
    @Autowired
    private RoomDao roomDao;

    @Autowired
    private ProjectDao projectDao;
    //新增房源且修改项目总面积
    public void addRoom(String rname, double roomArea, double roomRealArea, int pid,String state,int cid){
        ProjectTb project = projectDao.getProject(pid);
//        System.err.println(project);
        roomDao.addRoom(rname, roomArea, roomRealArea, pid, state,cid);
        double totalArea = project.getTotalArea()+roomArea;
        double totalRealArea = project.getTotalArea()+roomRealArea;
        roomDao.updateProjectTotalArea(totalArea,totalRealArea,pid);
    }
    //通过rid 获取房间信息
    public Room getRoomByRid(int rid){
        return roomDao.getRoomByRid(rid);
    }
    //获取某一项目下的所有房间资源
    public List<Room> getRoomsByPid(int pid){
        return roomDao.getRoomsByPid(pid);
    }
    //获取所有未出租房屋信息
    public List<Room> getUnrentRooms(){
        List<Room> rooms=roomDao.getUnrentRooms();
        for (Room room : rooms) {
            room.setPname(projectDao.getProject((int)room.getPid()).getPname());
        }
        return rooms;
    }

    //修改房源信息
    public void changeRoom(double roomArea,double roomRealArea,String rname,int rid){
        roomDao.changeRoom(roomArea, roomRealArea,rname,rid);
    }

}
